

<template>
      <div class="container">
      <h1 class="son">欢迎使用梦之海刻画插画生成工具</h1>
      <el-input style="width: 60%" class="son" type="textarea" rows="20" v-model="story" placeholder="请粘贴你的小说"></el-input>
<!--    <el-input v-model="style" placeholder="Style"></el-input>-->
<!--    <el-input v-model="desc" placeholder="Description"></el-input>-->
<!--    <el-button type="primary" @click="submit">Submit</el-button>-->
<!--      <div v-for="img in imgs">-->
<!--          <el-image :src="img" style="width: 100px; height: 100px"></el-image>-->
<!--      </div>-->
<!--      <el-input v-model="talk" placeholder="Talk"></el-input>-->
<!--      <el-button type="primary" @click="chat">Submit</el-button>-->
<!--      {{resp}}-->
            <div class="son">
                  <el-button type="primary" @click="generate">生成</el-button>
            </div>
      </div>

</template>
<script setup lang="ts">
import {onMounted, ref} from "vue";
import {wukongapi} from "@/utils/wukongapi";
import chatglmapi from "@/utils/chatglmapi";
import {Story} from "@/utils/story";
import router from "@/router";
import {storyStore} from "@/pinia/story";

let story = ref("")
let style = ref("");
let desc = ref("");
let imgs = ref([]);
let talk = ref("");
let resp = ref("123");
const store = storyStore();
const generate = ()=>{
      preProcess(story.value)

      router.push("/render")
}

function preProcess(text){
      let s = new Story(text);
      store.setStory(s)
}
const submit = () => {
  console.log(style.value);
  console.log(desc.value);
  wukongapi({style: style.value, desc: desc.value})
      .then((response) => {
          //todo
      }).catch((err)=>{
        console.log(err);
      })
}

const chat = ()=>{
    let history = [
        {
            "content": talk.value,
            "role": "user"
        }
    ]
    let callback =  (e,history)=>{
        if(e.event === "add"){
            resp.value += e.data;
        }else if(e.event === "finish"){
            console.log(resp.value)
            console.log("finish");
        }else if(e.event === "error"){
            console.log("error");
        }else if(e.event === "interrupted"){
            console.log("interrupted");
        }
    }
    chatglmapi(history,callback).then(()=>{

    })
}
</script>
<style>
.container{
      width: 100%;
      margin: auto;
      text-align: center;
}
.son{
      margin: 20px auto;
      text-align: center;
}
</style>
